<?php declare(strict_types=1);


namespace PinWuYun\domain\service\messageServer;

use Exception;
use PinWuYun\domain\service\messageServer\actions\TradePaid;
use PinWuYun\domain\service\youZanServer\LogServer;

/**
 * Created: by zhiJie
 * Date: 2021/7/2
 */
class ActionFactory
{
    /**
     * 消息处理工厂，根据type获取对应数据的处理对象
     * @throws Exception
     */
    public static function getAction(string $type)
    {
        /**  操作对象必须基础接口 messageImpl */
        $actions = [
            'trade_TradePaid' => TradePaid::class,
        ];
        $action = $actions[$type] ?? '';
        if(!$action) {
            $str = date('Y-m-d H:i:s') . PHP_EOL;
            $str .= 'action is not defined,type  name is '.$type . PHP_EOL;
            LogServer::errLog($str);
        }
        return (new $action);
    }

}